/*
 * Copyright 2006-2009 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package asphalt2.util
{
	/**
	 * 非同期オブジェクト
	 * Actionで呼び出されるfunctionで非同期処理を行いたい場合に、
	 * このクラスをfunctionの引き数に取ります。
	 *
	 * @author c9katayama
	 */
	public class Async
	{
		private var _nextFunction:Function;
		private var _stopFunction:Function;
		
		public function Async(next:Function,stop:Function=null){
			this._nextFunction = next;
			this._stopFunction = stop;
		}
		/**
		 * 次の処理を呼び出します。
		 * @param returnValue 非同期処理メソッドの戻り値
		 */
		public function gotoNext(returnValue:Object=null):void{
			if(_nextFunction != null){
				_nextFunction(returnValue);
				dispose();
			}
		}
		/**
		 * 次の処理を停止します。
		 */
		public function stop():void{
			if(_stopFunction != null){
				_stopFunction();
				dispose();
			}
		}
		public function get nextFunction():Function{
			return _nextFunction;
		}
		public function get stopFunction():Function{
			return _stopFunction;
		}
		protected function dispose():void{
			_nextFunction = null;
			_stopFunction = null;
		}
	}
}